/* Created on Aug 2, 2007 */
/**
 * 
 */
package com.xbang.core.struts.support;

import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.core.page.Result;
import com.xbang.core.service.BaseService;

/**
 * @author dev.zhang
 */
public class SearchAction extends SearchActionSupport {

	private static final long serialVersionUID = 783110686266556327L;

	@Autowired
	private BaseService baseService;

	private String sentenceTemplate;

	private Class persistentClass;

	private boolean pagination;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		if (pagination) {
			Result tempResult = baseService.listByPage(persistentClass, getPage());
			result = tempResult.getItems();
			page = tempResult.getPage();
		} else {
			result = baseService.loadAll(persistentClass);
		}
		return SUCCESS;
	}

	public void setBaseService(BaseService baseService) {
		this.baseService = baseService;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.tudou.core.struts.support.SearchActionSupport#resetCustomerSearchCriteria()
	 */
	public void resetCustomerSearchCriteria() {
		searchCriteria.put("sentenceTemplate", sentenceTemplate);
		searchCriteria.put("persistentClass", persistentClass);
		searchCriteria.put("pagination", pagination);
	}

}
